<?php
    @session_start();
    require_once 'shared-functions.php';
    require_once 'session.php';
    require_once 'masterpage.php';
	
	//***Get Entire Application Data***
	$link = connect_db();
	$ApplicantQuery = mysql_query("SELECT * FROM Applicant WHERE ApplicantID = '".$_GET['ApplicantID']."'")
	    or die("Select query failed while gathering applicant information:" . mysql_error());
	$EducationQuery = mysql_query("SELECT * FROM EducationHistory WHERE ApplicantID = '".$_GET['ApplicantID']."'")
	    or die("Select query failed while gathering education information:" . mysql_error());
	$EmergencyContactQuery = mysql_query("SELECT * FROM EmergencyContact WHERE ApplicantID = '".$_GET['ApplicantID']."'")
	    or die("Select query failed while gathering emergency contact information:" . mysql_error());
	$ExamQuery = mysql_query("SELECT * FROM ExamHistory WHERE ApplicantID = '".$_GET['ApplicantID']."'")
	    or die("Select query failed while gathering exam information:" . mysql_error());
	$GradesQuery = mysql_query("SELECT * FROM GradeHistory WHERE ApplicantID = '".$_GET['ApplicantID']."'")
	    or die("Select query failed while gathering grade information:" . mysql_error());
	$WitnessQuery = mysql_query("SELECT * FROM Witness WHERE ApplicantID = '".$_GET['ApplicantID']."'")
	    or die("Select query failed while gathering witness information:" . mysql_error());
	mysql_close($link);
	
	$ApplicantInfo = mysql_fetch_array($ApplicantQuery);
	$ApplicantInfo["DateOfBirth"] = changeDateFormat($ApplicantInfo["DateOfBirth"]);
	
	$QueryCnt = 0;
	$EducationArry = array();
	while ($EducationInfo = mysql_fetch_array($EducationQuery))
	{
		$EducationArry[$QueryCnt] = $EducationInfo;
		$EducationArry[$QueryCnt]["StartDate"] = changeDateFormat($EducationArry[$QueryCnt]["StartDate"]);
		$EducationArry[$QueryCnt]["EndDate"] = changeDateFormat($EducationArry[$QueryCnt]["EndDate"]);
		$QueryCnt++;
	}
	
	$EmergencyContactInfo = mysql_fetch_array($EmergencyContactQuery);
	
	$QueryCnt = 0;
	$ExamArry = array();
	while ($ExamInfo = mysql_fetch_array($ExamQuery))
	{
		$ExamArry[$QueryCnt] = $ExamInfo;
		$QueryCnt++;
	}
	
	$QueryCnt = 0;
	$GradesArry = array();
	while ($GradesInfo = mysql_fetch_array($GradesQuery))
	{
		$GradesArry[$QueryCnt] = $GradesInfo;
		$QueryCnt++;
	}
	
	$WitnessInfo = mysql_fetch_array($WitnessQuery);

function changeDateFormat($cdate){

	list($year,$month,$day)=explode("-",$cdate);

	return $day."/".$month."/".$year;
}
?>

<html>
<head>
    <title>Application Form for <?php echo $ApplicantInfo["Surname"]; ?></title>
<style type="text/css">	
	table.bordered {
		border-width: thin;
		border-style: solid;
		}
	
	table.outlined {
		border-collapse: collapse;
	}
	table.outlined th {
		border-width: thin;
		border-style: solid;
		padding: 3px;
	}
	table.outlined td {
		border-width: thin;
		border-style: solid;
		padding: 3px;
	}
</style>
</head>
<body>
<div id="divFormInfo">
<table>
	<tr>
	<td>
		<h3>APPLICATION FORM</h3>
	</td>
	</tr>
</table>
<br/><br/>
</div>

<div  id="divName">
<h4>1. Name</h4>

<b>TITLE:</b>
<br/>
	<input type="text" id="txtTitle" style="border:none" value="<?php echo $ApplicantInfo["Title"]; ?>"/>
<br/><br/>
<b>SURNAME:</b>
<br/>
	<input type="text" id="txtSurname" style="border:none" size="<?php echo strlen($ApplicantInfo["Surname"]);?>" value="<?php echo $ApplicantInfo["Surname"]; ?>"/>
<br/><br/>
<b>OTHER NAME:</b>
<br/>
	<input type="text" id="txtOthername" style="border:none" size="<?php echo strlen($ApplicantInfo["OtherName"]);?>" value="<?php echo $ApplicantInfo["OtherName"]; ?>"/>
	<br/>
<br/><br/>
</div>

<div id="divDOB">
<h4>2. Date of Birth (day, month, year)</h4>
<input type="text" id="txtDOB" style="border:none" value="<?php echo $ApplicantInfo["DateOfBirth"];?>"/>
<br/><br/>
</div>

<div id="divSex">
<h4>3. Sex</h4>
<input type="text" id="txtSex" style="border:none" value="<?php echo $ApplicantInfo["Sex"]; ?>"/>
<br/><br/>
</div>

<div id="divAddress">
<h4>4. Address to which communication regarding this application should be sent:</h4>
	<input type="text" id="txtAddress" style="border:none" size="<?php echo strlen($ApplicantInfo["Address"]);?>" value="<?php echo $ApplicantInfo["Address"]; ?>"/>
<br/><br/>
	<b>E-Mail Address:</b>
	<input type="text" id="txtEmail" style="border:none" size="<?php echo strlen($ApplicantInfo["Email"])+10;?>" value="<?php echo $ApplicantInfo["Email"]; ?>"/>
<br/>
	<b>Tel. No:</b>
	<input type="text" id="txtPhone" style="border:none" size="<?php echo strlen($ApplicantInfo["Telephone"]);?>" value="<?php echo $ApplicantInfo["Telephone"]; ?>"/>
<br/><br/>
</div>

<div id="divGeographics">
<h4>5. Geographics</h4>
<table>
	<tr>
		<td><b>i.</b></td>
		<td><b>Place of Birth</b></td>
		<td><input type="text" id="txtPlaceofbirth" style="border:none" size="<?php echo strlen($ApplicantInfo["Birthplace"]);?>" value="<?php echo $ApplicantInfo["Birthplace"]; ?>"/></td>
	</tr><tr>
		<td><b>ii.</b></td>
		<td><b>Nationality</b></td>
		<td><input type="text" id="txtNationality" style="border:none" size="<?php echo strlen($ApplicantInfo["Nationality"]);?>" value="<?php echo $ApplicantInfo["Nationality"]; ?>"/></td>
	</tr><tr>
		<td><b>iii.</b></td>
		<td><b>Home Town</b></td>
		<td><input type="text" id="txtHometown" style="border:none" size="<?php echo strlen($ApplicantInfo["Hometown"]);?>" value="<?php echo $ApplicantInfo["Hometown"]; ?>"/></td>
	</tr><tr>
		<td><b>iv.</b></td>
		<td><b>Region and Country</b></td>
		<td><input type="text" id="txtRegion" style="border:none" size="<?php echo strlen($ApplicantInfo["Region"]);?>" value="<?php echo $ApplicantInfo["Region"]; ?>"/></td>
	</tr><tr>
		<td><b>v.</b></td>
		<td><b>Religion</b></td>
		<td><input type="text" id="txtReligion" style="border:none" size="<?php echo strlen($ApplicantInfo["Religion"]);?>" value="<?php echo $ApplicantInfo["Religion"]; ?>"/></td>
	</tr>
</table>
<br/><br/>
</div>

<div id="divImpairments">
<b>6. impairments</b>
    <textarea cols="50" rows="<?php echo strlen($ApplicantInfo["Impairment"])/50;?>" id="txtImpairment" name="txtImpairment" value=""><?php echo $ApplicantInfo["Impairment"]; ?></textarea>	
<br/><br/>
</div>

<div id="divEducation">
<h4>8. Education</h4>
<table class="outlined">
	<tr>
		<td valign="top"><center>Name of Secondary School/College & Location</center></td>
		<td valign="top"><center>Offices Held</center></td>
		<td><center>Attended Dates<br>(day, month, year)</center></td>
		<td rowspan="7" style="border:none">
		</td>
	</tr><tr>
		<td><input type="text" id="txtSecschools1" style="border:none" size="<?php echo strlen($EducationArry[0]["SchoolNameLocation"]);?>" value="<?php echo $EducationArry[0]["SchoolNameLocation"]; ?>"/></td>
		<td><input type="text" id="txtOffices1" style="border:none" size="<?php echo strlen($EducationArry[0]["OfficesHeld"]);?>" value="<?php echo $EducationArry[0]["OfficesHeld"]; ?>"/></td>
		<td>
			From: 
			<input type="text" id="txtSchoolsStart1" style="border:none" value="<?php echo $EducationArry[0]["StartDate"];?>"/>
		</td>
	</tr><tr>
		<td></td><td></td>
		<td>
			To: 
			<input type="text" id="txtSchoolsEnd1" style="border:none" value="<?php echo $EducationArry[0]["EndDate"];?>"/>
		</td>
	</tr><tr>
		<td><input type="text" id="txtSecschools2" style="border:none" size="<?php echo strlen($EducationArry[1]["SchoolNameLocation"]);?>" value="<?php echo $EducationArry[1]["SchoolNameLocation"]; ?>"/></td>
		<td><input type="text" id="txtOffices2" style="border:none" size="<?php echo strlen($EducationArry[1]["OfficesHeld"]);?>" value="<?php echo $EducationArry[1]["OfficesHeld"]; ?>"/></td>
		<td>
			From: 
			<input type="text" id="txtSchoolsStart2" style="border:none" value="<?php echo $EducationArry[1]["StartDate"];?>"/>
		</td>
	</tr><tr>
		<td></td><td></td>
		<td>
			To: 
			<input type="text" id="txtSchoolsEnd2" style="border:none" value="<?php echo $EducationArry[1]["EndDate"];?>"/>
		</td>
	</tr><tr>
		<td><input type="text" id="txtSecschools3" style="border:none" size="<?php echo strlen($EducationArry[2]["SchoolNameLocation"]);?>" value="<?php echo $EducationArry[2]["SchoolNameLocation"]; ?>"/></td>
		<td><input type="text" id="txtOffices3" style="border:none" size="<?php echo strlen($EducationArry[2]["OfficesHeld"]);?>" value="<?php echo $EducationArry[2]["OfficesHeld"]; ?>"/></td>
		<td>
			From: 
			<input type="text" id="txtSchoolsStart3" style="border:none" value="<?php echo $EducationArry[2]["StartDate"];?>"/>
		</td>
	</tr><tr>
		<td></td><td></td>
		<td>
			To: 
			<input type="text" id="txtSchoolsEnd2" style="border:none" value="<?php echo $EducationArry[2]["EndDate"];?>"/>
		</td>
	</tr>
</table>
<br/><br/>
</div>

<div id="divExam">
<h4>9. Examination Details:</h4>
<table class="outlined">
	<tr>
		<td width="125"><b>Attempts</b></td>
		<td><center>1st</center></td>
		<td><center>2nd</center></td>
		<td><center>3rd</center></td>
	</tr><tr>
		<td><b>Name</b></td>
		<td><input type="text" id="txtExamName1" style="border:none" size="<?php echo strlen($ExamArry[0]["ExamName"]);?>" value="<?php echo $ExamArry[0]["ExamName"]; ?>"/></td>
		<td><input type="text" id="txtExamYear1" style="border:none" size="<?php echo strlen($ExamArry[0]["ExamYear"]);?>" value="<?php echo $ExamArry[0]["ExamYear"]; ?>"/></td>
		<td><input type="text" id="txtExamIndex1" style="border:none" size="<?php echo strlen($ExamArry[0]["ExamIndex"]);?>" value="<?php echo $ExamArry[0]["ExamIndex"]; ?>"/></td>
	</tr><tr>
		<td><b>Year</b></td>
		<td><input type="text" id="txtExamName2" style="border:none" size="<?php echo strlen($ExamArry[1]["ExamName"]);?>" value="<?php echo $ExamArry[1]["ExamName"]; ?>"/></td>
		<td><input type="text" id="txtExamYear2" style="border:none" size="<?php echo strlen($ExamArry[1]["ExamYear"]);?>" value="<?php echo $ExamArry[1]["ExamYear"]; ?>"/></td>
		<td><input type="text" id="txtExamIndex2" style="border:none" size="<?php echo strlen($ExamArry[1]["ExamIndex"]);?>" value="<?php echo $ExamArry[1]["ExamIndex"]; ?>"/></td>
	</tr><tr>
		<td><b>Index No(s)</b></td>
		<td><input type="text" id="txtExamName3" style="border:none" size="<?php echo strlen($ExamArry[2]["ExamName"]);?>" value="<?php echo $ExamArry[2]["ExamName"]; ?>"/></td>
		<td><input type="text" id="txtExamYear3" style="border:none" size="<?php echo strlen($ExamArry[2]["ExamYear"]);?>" value="<?php echo $ExamArry[2]["ExamYear"]; ?>"/></td>
		<td><input type="text" id="txtExamIndex3" style="border:none" size="<?php echo strlen($ExamArry[2]["ExamIndex"]);?>" value="<?php echo $ExamArry[2]["ExamIndex"]; ?>"/></td>
	</tr>
</table>
<br/><br/>
</div>

<div id="divGrades">
<h4>10. Grades Obtained</h4>
<table class="outlined">
	<tr>
		<td><center><b>Subjects</b></center></td>
		<td colspan="3"><center><b>Grades</b></center></td>
	</tr><tr>
		<td></td>
		<td><center>1st Attempt</center></td>
		<td><center>2nd Attempt</center></td>
		<td><center>3rd Attempt</center></td>
	</tr><tr>
		<td><input type="text" id="txtGradesSubject1" style="border:none" size="<?php echo strlen($GradesArry[0]["Subject"]);?>" value="<?php echo $GradesArry[0]["Subject"]; ?>"/></td>
		<td><input type="text" id="txtGradesFirst1" style="border:none" size="<?php echo strlen($GradesArry[0]["Attempt1"]);?>" value="<?php echo $GradesArry[0]["Attempt1"]; ?>"/></td>
		<td><input type="text" id="txtGradesSecond1" style="border:none" size="<?php echo strlen($GradesArry[0]["Attempt2"]);?>" value="<?php echo $GradesArry[0]["Attempt2"]; ?>"/></td>
		<td><input type="text" id="txtGradesThird1" style="border:none" size="<?php echo strlen($GradesArry[0]["Attempt3"]);?>" value="<?php echo $GradesArry[0]["Attempt3"]; ?>"/></td>
	</tr><tr>
		<td><input type="text" id="txtGradesSubject2" style="border:none" size="<?php echo strlen($GradesArry[1]["Subject"]);?>" value="<?php echo $GradesArry[1]["Subject"]; ?>"/></td>
		<td><input type="text" id="txtGradesFirst2" style="border:none" size="<?php echo strlen($GradesArry[1]["Attempt1"]);?>" value="<?php echo $GradesArry[1]["Attempt1"]; ?>"/></td>
		<td><input type="text" id="txtGradesSecond2" style="border:none" size="<?php echo strlen($GradesArry[1]["Attempt2"]);?>" value="<?php echo $GradesArry[1]["Attempt2"]; ?>"/></td>
		<td><input type="text" id="txtGradesThird2" style="border:none" size="<?php echo strlen($GradesArry[1]["Attempt3"]);?>" value="<?php echo $GradesArry[1]["Attempt3"]; ?>"/></td>
	</tr><tr>
		<td><input type="text" id="txtGradesSubject3" style="border:none" size="<?php echo strlen($GradesArry[2]["Subject"]);?>" value="<?php echo $GradesArry[2]["Subject"]; ?>"/></td>
		<td><input type="text" id="txtGradesFirst3" style="border:none" size="<?php echo strlen($GradesArry[2]["Attempt1"]);?>" value="<?php echo $GradesArry[2]["Attempt1"]; ?>"/></td>
		<td><input type="text" id="txtGradesSecond3" style="border:none" size="<?php echo strlen($GradesArry[2]["Attempt2"]);?>" value="<?php echo $GradesArry[2]["Attempt2"]; ?>"/></td>
		<td><input type="text" id="txtGradesThird3" style="border:none" size="<?php echo strlen($GradesArry[2]["Attempt3"]);?>" value="<?php echo $GradesArry[2]["Attempt3"]; ?>"/></td>
	</tr><tr>
		<td><input type="text" id="txtGradesSubject4" style="border:none" size="<?php echo strlen($GradesArry[3]["Subject"]);?>" value="<?php echo $GradesArry[3]["Subject"]; ?>"/></td>
		<td><input type="text" id="txtGradesFirst4" style="border:none" size="<?php echo strlen($GradesArry[3]["Attempt1"]);?>" value="<?php echo $GradesArry[3]["Attempt1"]; ?>"/></td>
		<td><input type="text" id="txtGradesSecond4" style="border:none" size="<?php echo strlen($GradesArry[3]["Attempt2"]);?>" value="<?php echo $GradesArry[3]["Attempt2"]; ?>"/></td>
		<td><input type="text" id="txtGradesThird4" style="border:none" size="<?php echo strlen($GradesArry[3]["Attempt3"]);?>" value="<?php echo $GradesArry[3]["Attempt3"]; ?>"/></td>
	</tr><tr>
		<td><input type="text" id="txtGradesSubject5" style="border:none" size="<?php echo strlen($GradesArry[4]["Subject"]);?>" value="<?php echo $GradesArry[4]["Subject"]; ?>"/></td>
		<td><input type="text" id="txtGradesFirst5" style="border:none" size="<?php echo strlen($GradesArry[4]["Attempt1"]);?>" value="<?php echo $GradesArry[4]["Attempt1"]; ?>"/></td>
		<td><input type="text" id="txtGradesSecond5" style="border:none" size="<?php echo strlen($GradesArry[4]["Attempt2"]);?>" value="<?php echo $GradesArry[4]["Attempt2"]; ?>"/></td>
		<td><input type="text" id="txtGradesThird5" style="border:none" size="<?php echo strlen($GradesArry[4]["Attempt3"]);?>" value="<?php echo $GradesArry[4]["Attempt3"]; ?>"/></td>
	</tr><tr>
		<td><input type="text" id="txtGradesSubject6" style="border:none" size="<?php echo strlen($GradesArry[5]["Subject"]);?>" value="<?php echo $GradesArry[5]["Subject"]; ?>"/></td>
		<td><input type="text" id="txtGradesFirst6" style="border:none" size="<?php echo strlen($GradesArry[5]["Attempt1"]);?>" value="<?php echo $GradesArry[5]["Attempt1"]; ?>"/></td>
		<td><input type="text" id="txtGradesSecond6" style="border:none" size="<?php echo strlen($GradesArry[5]["Attempt2"]);?>" value="<?php echo $GradesArry[5]["Attempt2"]; ?>"/></td>
		<td><input type="text" id="txtGradesThird6" style="border:none" size="<?php echo strlen($GradesArry[5]["Attempt3"]);?>" value="<?php echo $GradesArry[5]["Attempt3"]; ?>"/></td>
	</tr><tr>
		<td><input type="text" id="txtGradesSubject7" style="border:none" size="<?php echo strlen($GradesArry[6]["Subject"]);?>" value="<?php echo $GradesArry[6]["Subject"]; ?>"/></td>
		<td><input type="text" id="txtGradesFirst7" style="border:none" size="<?php echo strlen($GradesArry[6]["Attempt1"]);?>" value="<?php echo $GradesArry[6]["Attempt1"]; ?>"/></td>
		<td><input type="text" id="txtGradesSecond7" style="border:none" size="<?php echo strlen($GradesArry[6]["Attempt2"]);?>" value="<?php echo $GradesArry[6]["Attempt2"]; ?>"/></td>
		<td><input type="text" id="txtGradesThird7" style="border:none" size="<?php echo strlen($GradesArry[6]["Attempt3"]);?>" value="<?php echo $GradesArry[6]["Attempt3"]; ?>"/></td>
	</tr><tr>
		<td><input type="text" id="txtGradesSubject8" style="border:none" size="<?php echo strlen($GradesArry[7]["Subject"]);?>" value="<?php echo $GradesArry[7]["Subject"]; ?>"/></td>
		<td><input type="text" id="txtGradesFirst8" style="border:none" size="<?php echo strlen($GradesArry[7]["Attempt1"]);?>" value="<?php echo $GradesArry[7]["Attempt1"]; ?>"/></td>
		<td><input type="text" id="txtGradesSecond8" style="border:none" size="<?php echo strlen($GradesArry[7]["Attempt2"]);?>" value="<?php echo $GradesArry[7]["Attempt2"]; ?>"/></td>
		<td><input type="text" id="txtGradesThird8" style="border:none" size="<?php echo strlen($GradesArry[7]["Attempt3"]);?>" value="<?php echo $GradesArry[7]["Attempt3"]; ?>"/></td>
	</tr>
</table>
<br/><br/>
</div>

<div id="divEmergencyContact">
<h4>11. Emergency Contact Information</h4>
<table>
	<tr>
		<td><b>Name of Parent or Guardian</b></td>
		<td><input type="text" id="txtParentName" style="border:none" size="<?php echo strlen($EmergencyContactInfo["ContactName"]);?>" value="<?php echo $EmergencyContactInfo["ContactName"]; ?>"/></td>
	</tr><tr>
		<td><b>Relationship to Candidate</b></td>
		<td><input type="text" id="txtParentRelation" style="border:none" size="<?php echo strlen($EmergencyContactInfo["Relationship"]);?>" value="<?php echo $EmergencyContactInfo["Relationship"]; ?>"/></td>
	</tr><tr>
		<td><b>Address of Parent or Guardian</b></td>
		<td><input type="text" id="txtParentAddress" style="border:none" size="<?php echo strlen($EmergencyContactInfo["Address"]);?>" value="<?php echo $EmergencyContactInfo["Address"]; ?>"/></td>
	</tr><tr>
		<td><b>Tel:</b><input type="text" id="txtParentPhone" style="border:none" size="<?php echo strlen($EmergencyContactInfo["Telephone"]);?>" value="<?php echo $EmergencyContactInfo["Telephone"]; ?>"/></td>
		<td><b>E-mail:</b><input type="text" id="txtParentEMail" style="border:none" size="<?php echo strlen($EmergencyContactInfo["Email"])+5;?>" value="<?php echo $EmergencyContactInfo["Email"]; ?>"/></td>
	</tr><tr>
		<td><b>Occupation of Parent or Guardian</b></td>
		<td><input type="text" id="txtParentOccupation" style="border:none" size="<?php echo strlen($EmergencyContactInfo["Occupation"]);?>" value="<?php echo $EmergencyContactInfo["Occupation"]; ?>"/></td>
	</tr>
</table>
<br/>
</div>

<div id="divProgram">
<h4>12. Program of Inteded Study</h4>
	<input type="radio" id="rdoMLA" name="program" value="MLA" <?php if($ApplicantInfo["Program"]=="MLA"){echo "checked";}?>/>
	Medical Laboratory Assistant (MLA)
	<br/>
	<input type="radio" id="rdoMLT" name="program" value="MLT" <?php if($ApplicantInfo["Program"]=="MLT"){echo "checked";}?>/>
	Medical Laboratory Technitian (MLT)
	<br/>
	<input type="radio" id="rdoDMLT" name="program" value="DMLT" <?php if($ApplicantInfo["Program"]=="DMLT"){echo "checked";}?>/>
	Medical Laboratory Technologist (DMLT)
<br/><br/><br/>
</div>

<div id="divDeclaration">
<h4>Witness Information</h4>
<table>
	<tr>
		<td>Name:</td>
		<td><input type="text" id="txtWitnessName" style="border:none" size="<?php echo strlen($WitnessInfo["WitnessName"]);?>" value="<?php echo $WitnessInfo["WitnessName"]; ?>"/></td>
	</tr><tr>
		<td>Status:</td>
		<td><input type="text" id="txtWitnessStatus" style="border:none" size="<?php echo strlen($WitnessInfo["Status"]);?>" value="<?php echo $WitnessInfo["Status"]; ?>"/></td>
	</tr><tr>
		<td>Address:</td>
		<td><input type="text" id="txtWitnessAddress" style="border:none" size="<?php echo strlen($WitnessInfo["Address"]);?>" value="<?php echo $WitnessInfo["Address"]; ?>"/></td>
	</tr>
</table>
<br/>
</div>
</body>
</html>